import router from '@/router';
import { clearLocal } from '@/utils/auth';
import { computed, inject, reactive } from 'vue';
import { useDark, useToggle } from '@vueuse/core';
import { useAppPinia } from '@pinia/modules/app';

export default function importConfig() {
  const base = reactive({
    userInFo: null,
  });
  const theme = computed(() => {
    return appPinia.theme;
  });
  const appPinia = useAppPinia();
  const topMenu = computed(() => {
    return appPinia.topMenu && appPinia.menu;
  });

  const isDark = useDark({
    selector: 'body',
    attribute: 'arco-theme',
    valueDark: 'dark',
    valueLight: 'light',
    storageKey: 'arco-theme',
    onChanged(dark: boolean) {
      // overridden default behavior
      appPinia.toggleTheme(dark);
    },
  });
  const toggleTheme = useToggle(isDark);

  const handleToggleTheme = () => {
    toggleTheme();
  };

  /**
   * @distributeTheTasks 分发操作
   * 2行能完成的代码请在方法体中操作,如果不是请创建新的方法并分发调用
   * @param param  操作名称
   * @param paramA 可能需要传递的参数
   * @param paramB 可能需要传递的参数
   */
  const distributeTheTasks = (param: any) => {
    console.log(param);
    if (param == '退出登录') {
      // memberUserLogout().then((res: any) => {
      //   if (res.code == 200) {
      // clearLocal();
      localStorage.clear();
      // location.reload();
      router.push('/login');
      //   }
      // });
    } else if (param == '修改密码') {
    } else if (param == '个人中心') {
      router.push('/individualCenter');
    }
  };

  const toggleDrawerMenu = inject('toggleDrawerMenu') as () => void;

  return {
    base,
    theme,
    topMenu,
    appPinia,
    handleToggleTheme,
    distributeTheTasks,
    toggleDrawerMenu,
  };
}
